package com.briup.jz.service.impl;

import com.briup.jz.bean.OrderLine;
import com.briup.jz.bean.OrderLineExample;
import com.briup.jz.bean.extend.OrderLineExtend;
import com.briup.jz.dao.OrderLineMapper;
import com.briup.jz.dao.extend.OrderLineExtendMapper;
import com.briup.jz.service.IOrderLineService;
import com.briup.jz.utils.CustomerException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: jz
 * @description: 订单列表业务实现类
 * @author: catmilko
 * @create: 2020/6/12 15:58
 **/

@Service
public class OrderLineServiceImpl implements IOrderLineService {

    @Resource
    private OrderLineMapper orderLineMapper;

    @Resource
    private OrderLineExtendMapper orderLineExtendMapper;


    @Override
    public List<OrderLine> findAll() {
        OrderLineExample example = new OrderLineExample();
        return orderLineMapper.selectByExample(example);
    }

    @Override
    public void saveOrUpdate(OrderLine orderLine) throws CustomerException {
        if (orderLine.getId() == null){
            orderLineMapper.updateByPrimaryKey(orderLine);
        }else{
            orderLineMapper.insert(orderLine);
        }

    }

    @Override
    public void deleteById(long id) throws CustomerException {
        OrderLine orderLine = orderLineMapper.selectByPrimaryKey(id);
        //先判断该id对应的数据是否存在？
        if (orderLine != null){
            //不存在，报错
            throw new CustomerException("删除失败，要删除的数据不存在");
        }
        orderLineMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<OrderLineExtend> findAllAboutProduct() {
        return orderLineExtendMapper.selectAllAboutProduct();
    }

}
